<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<!--{include file='comm/header.tpl'}-->
<title><!--{$promotionInfo->title}-->-活动配置</title>
<!--{include file="comm/icheck.tpl"}-->
<style>.flexigrid{margin:10px;}</style> 
<!--{include file='comm/comm_cal.tpl'}-->
<!--{include file='comm/comm_pic.tpl'}-->
<script>
	var GIFT_ARRAY = {};
</script>
</head>
<body>
	<div style="width:100%;">
        <div class="container">
            <div class="comm_crub">
                <span class="now_crub">活动配置：
                    <span id="title">
                        <!--{$promotionInfo->title}-->
                    </span>
                </span>
            </div>
			<div class="comm_content">
				<!--{if isset($error_msg)}-->
					<div class="comm-box">
		                <div style="position:relative;color: red;">
		                    <!--{$error_msg}-->
		                </div>
		            </div>
	            <!--{else}-->
					<div>
						<form id="sendForm" name="sendForm" class="form-horizontal" onsubmit="return false;">
							<div>
                                <!--{foreach from=$systemConfig item=config}-->
                                    <!--{if $config->config_key == 'payTypeID'}-->
                                        <!--支付方式-->
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label"><span class="red">*</span> <!--{$config->config_value}-->：</label>
                                            <div class="col-sm-10">
                                                <!--{foreach from=$pay_type_array item=payType}-->
                                                <div class="fl" style="margin: 0px 10px 10px 0px;">
                                                    <input type="checkbox" class="square-radio" id="payType-checkbox-<!--{$payType.payTypeID}-->" name="payTypeID" value="<!--{$payType.payTypeID}-->" <!--{if isset($promotionInfo->payTypeID) && $payType.payTypeID|in_array:$promotionInfo->payTypeID}--> checked="checked" <!--{/if}--> >
                                                    <label for="payType-checkbox-<!--{$payType.payTypeID}-->"><!--{$payType.payTypeName}--></label>
                                                </div>
                                                <!--{/foreach}-->
                                            </div>
                                        </div>
                                    <!--{elseif $config->config_key == 'paymentID'}-->
                                        <!--付款方式-->
                                        <div class="form-group" id="payment" style="<!--{if !$payment_array}-->display:none<!--{/if}-->">
                                            <label class="col-sm-2 control-label"><!--{$config->config_value}-->：</label>
                                            <div class="col-sm-10">
                                                <!--{foreach from=$payment_array item=payment}-->
                                                <div class="fl" style="margin: 0px 10px 10px 0px;">
                                                    <input type="checkbox" class="square-radio" id="payment-checkbox-<!--{$payment.id}-->" name="paymentID" value="<!--{$payment.id}-->" <!--{if isset($select_paymentID) && $payment.id|in_array:$select_paymentID}--> checked="checked" <!--{/if}--> >
                                                    <label for="payment-checkbox-<!--{$payment.id}-->"><!--{$payment.name}--></label>
                                                </div>
                                                <!--{/foreach}-->
                                            </div>
                                        </div>
                                    <!--{elseif $config->config_key == 'billPromotion'}-->
                                        <!--促销渠道-->
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label"><span class="red">*</span> <!--{$config->config_value}-->：</label>
                                            <div class="col-sm-10">
                                                <!--{foreach from=$promotion_channel_array item=promotionChannel}-->
                                                <div class="fl" style="margin: 0px 10px 10px 0px;">
                                                    <input type="radio" class="square-radio"name="billPromotion" value="<!--{$promotionChannel.itemID}-->" <!--{if isset($activityConfig.billPromotion) && $activityConfig.billPromotion eq $promotionChannel.itemID}--> checked="checked" <!--{/if}--> >
                                                    <label for="promotionChannel-checkbox-<!--{$promotionChannel.itemID}-->"><!--{$promotionChannel.itemName}--></label>
                                                </div>
                                                <!--{/foreach}-->
                                            </div>
                                        </div>
                                    <!--{elseif $config->config_key == 'start_time' || $config->config_key == 'end_time'}-->
                                        <!--活动开始时间/活动结束时间-->
                                        <div class="form-group">
                                            <div>
                                                <label class="col-sm-2 control-label"><span class="red">*</span> <!--{$config->config_value}-->：</label>
                                                <div class="col-sm-3">
                                                    <input type="text" class="form-control" id="<!--{$config->config_key}-->" name="<!--{$config->config_key}-->" readonly=""  value="<!--{$activityConfig[$config->config_key]}-->" >
                                                </div>
                                            </div>
                                        </div>
                                    <!--{elseif $config->config_key == 'send_start_date' || $config->config_key == 'send_end_date'}-->
                                        <!--配送开始时间/配送结束时间-->
                                        <div class="form-group">
                                            <div>
                                                <label class="col-sm-2 control-label"><span class="red">*</span> <!--{$config->config_value}-->：</label>
                                                <div class="col-sm-2" style="width:130px">
                                                    <input type="text" class="form-control w100" id="<!--{$config->config_key}-->" name="<!--{$config->config_key}-->" readonly="" value="<!--{$activityConfig[$config->config_key]}-->">
                                                </div>
                                            </div>
                                        </div>
                                    <!--{elseif $config->config_key == 'config_code'}-->
                                        <!--活动特征码-->
                                        <div class="form-group">
                                            <label for="<!--{$config->config_key}-->" class="col-sm-2 control-label"><span class="red">*</span> <!--{$config->config_value}-->：</label>
                                            <div class="col-sm-6">
                                                <input type="text" class="form-control w300" id="<!--{$config->config_key}-->" name="<!--{$config->config_key}-->" value='<!--{$config_code}-->' >
                                            </div>
                                            <div class="col-sm-4">
                                                <!--{$config->config_remark}-->
                                            </div>
                                        </div>
                                    <!--{else}-->
                                        <div class="form-group">
                                            <label for="description" class="col-sm-2 control-label"> <!--{$config->config_value}-->：</label>
                                            <div class="col-sm-6">
                                                <textarea  class="form-control" id="<!--{$config->config_key}-->" name="<!--{$config->config_key}-->"><!--{$activityConfig[$config->config_key]}--></textarea>
                                            </div>
                                            <div class="col-sm-4">
                                                <!--{$config->config_remark}-->
                                            </div>
                                        </div>
                                    <!--{/if}-->
                                <!--{/foreach}-->
							</div>
						</form>
					</div>
				<!--{/if}-->
			</div>
		</div>
		</div>
        <div class="popup-footer">
	        <div class="rectbox tac" style="margin: 20px;">
	        	<input type="hidden" id ="dataCache" name="dataCache" value="">
	            <input type="button" class="btn btn-success" onclick="promotion.check();" value="保存" />&nbsp;&nbsp;&nbsp;
	            <input type="button" class="btn btn-default" onclick="E.closeWindows();" value="关闭" />
	        </div>
	    </div>
	</div>
	<script>
    $(window).ready(function() {
        $('.square-radio').iCheck({
            checkboxClass: 'icheckbox_square-blue',
            radioClass: 'iradio_square-blue',
            increaseArea: '20%' // optional
        });
        $('input[name="use_card"]').on('ifChecked', function(event){
            var use_card = $(this).val();
            if ( use_card == 0 ) {
                $("#setUseCard").hide();

            } else if ( use_card == 2 ) {
                $("#setUseCard").hide();

            } else {
                $("#setUseCard").show();
            }
        });
        $('input[name="payTypeID"]').on('ifChanged', function() {
            promotion.getPaymen();
        });
    });
    if( GIFT_ARRAY )
        $("#dataCache").data( "goods" , GIFT_ARRAY );

    $('#start_time').datetimepicker({timeFormat:'HH:mm:ss',showHour: true,showMinute: true,showSecond: true,});
    $('#end_time').datetimepicker({timeFormat:'HH:mm:ss',showHour: true,showMinute: true,showSecond: true,hour: 23,minute: 59,second:59,});
    $('#send_start_date').datetimepicker();
    $('#send_end_date').datetimepicker();

    var GTYPE = "<!--{$promotionInfo->type}-->" ;

    var promotion = {

        //检查数据
        check: function() {
            this.dt = E.getFormValues("sendForm") ;

            var concessions = $.trim($("#concessions_" + GTYPE).val()) ;
            var error_msg = "";
            if (this.dt.config_code == "")
                error_msg += "活动特征码不能为空<br />";

            if (!E.isDate(this.dt.start_time))
                error_msg += "促销开始时间格式不对<br />";

             if (!E.isDate(this.dt.end_time))
                error_msg += "促销结束时间格式不对<br />";

            if(this.dt.start_time > this.dt.end_time)
                error_msg += "促销开始时间不能大于结束时间<br />";

            if(this.dt.send_start_time > this.dt.send_end_time)
                error_msg += "配送开始时间不能大于结束时间<br />";

            if (error_msg != "")
                E.alert(error_msg);
            else
                promotion.add() ;
        },

        //保存促销信息
        add: function() {
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/promotion/promotionGoods.ajax?operFlg=200&act=save" ,
                dataType: "JSON",
                data: this.dt,
                success: function( o ) {
                    if (o.code == 200) {
                        E.opener("promotion.load");
                        E.alert(o.message, 2, "E.closeWindows");
                    } else {
                        E.alert(o.message);
                    }
                }
            });
        },

        //查询支付方式下的付款方式
        getPaymen:function( payTypeID ){

            var dt = E.getFormValues("sendForm");

            E.loadding.open('正在努力加载中...');

            E.ajax_post({
                url: '/invokingAjax-backend/promotion/promotionGoods.ajax?operFlg=7',
                data: dt,
                call: 'promotion.getPaymenCallBack'
            });
        },

        getPaymenCallBack:function( result_data ){

            E.loadding.close();
            if( result_data.code == 200 ){

                if(result_data.data){
                    var html = '<label class="col-sm-2 control-label">付款方式：</label>';
                    html += '<div class="col-sm-10">'
                    $.each(result_data.data,function(k,v){
                        var checked = '';
                        if(v.select == 1){
                            checked = 'checked';
                        }
                        html += '<div class="fl" style="margin: 0px 10px 10px 0px;">';
                        html += '<input type="checkbox" class="square-radio-payment" id="payment-checkbox-'+ v.paymentID +'" name="paymentID" value="'+ v.paymentID +'" '+ checked +'>';
                        html += '<label for="payType-checkbox-'+ v.paymentID +'">'+ v.name +'</label>';
                        html += '</div>';

                    });
                    html += '</div>';

                    $("#payment").html(html).show()

                    $('.square-radio-payment').iCheck({
                        checkboxClass: 'icheckbox_square-blue',
                        radioClass: 'iradio_square-blue',
                        increaseArea: '20%' // optional
                    });
                }else{
                    $("#payment").empty().hide();
                }
            }else{
                E.alert(result_data.message);
            }
        }
    };
	</script>
</body>
</html>